

class Solution:

    def decodeString(self, s:str) -> str:

        stack, res, multi = [], "", 0

        for c in s:

            if c == "[":

                stack.append([multi, res])
                res, multi = "", 0
            elif c == "]":

                cur_multi, cur_res = stack.pop()

                res = cur_res + cur_multi * res

            elif '0' <= c <= '9':
                # 如果遇到了多位数
                multi = multi * 10 + int(c)

            else:
                
                res += c
            

        return res






